package com.snailct.bpp.router.datachange.service;

import com.snailct.bpp.router.datachange.SynDealWithMessage;

/**
 * Created by huangxa on 2016/6/17.
 */
public class AcceptMessageService implements IAcceptMessage {
    public String acceptMessage(String xmlStr) {
        boolean isMessage = false;
        String mingXmlStr = "";
        try{
            //DES解密
            mingXmlStr = xmlStr;
            isMessage = true;
        }catch (Exception e){
            isMessage = false;
            e.printStackTrace();
        }
        //解密正常
        if(isMessage){
            boolean checkXMLlg = false;
            boolean checkXMLSchema = false;
            //验证报文格式
            checkXMLlg = true;
            checkXMLSchema = true;

            //如果报文合法
            if(checkXMLlg&&checkXMLSchema){
                //如果同步处理
                if(SynDealWithMessage.isSyn(mingXmlStr)){
                    return SynDealWithMessage.synDealWithMessage(mingXmlStr);
                }else{//异步处理
                    AcceptMessage accept = new AcceptMessage();
                    accept.setXmlStr(mingXmlStr);
                    accept.insertXMLStr();
                    return "1";
                }
            }
        }
        return null;
    }
}
